import request from '@/hooks/utils/http'
import { AxiosPromise } from 'axios'

export class CategoryService{

    /**
     * 查询流程分类列表
     * @param query
     * @returns {*}
     */

    static listCategory = (query?: CategoryQuery): AxiosPromise<CategoryVO[]> => {
        return request({
            url: '/workflow/category/list',
            method: 'get',
            params: query
        });
    };

    /**
     * 查询流程分类详细
     * @param categoryId
     */
    static getCategory = (categoryId: string | number): AxiosPromise<CategoryVO> => {
        return request({
            url: '/workflow/category/' + categoryId,
            method: 'get'
        });
    };

    /**
     * 新增流程分类
     * @param data
     */
    static addCategory = (data: CategoryForm) => {
        return request({
            url: '/workflow/category',
            method: 'post',
            data: data
        });
    };

    /**
     * 修改流程分类
     * @param data
     */
    static updateCategory = (data: CategoryForm) => {
        return request({
            url: '/workflow/category',
            method: 'put',
            data: data
        });
    };

    /**
     * 删除流程分类
     * @param categoryId
     */
    static delCategory = (categoryId: string | number | Array<string | number>) => {
        return request({
            url: '/workflow/category/' + categoryId,
            method: 'delete'
        });
    };

    /**
     * 获取流程分类树列表
     * @param query 流程实例id
     * @returns
     */
    static categoryTree = (query?: CategoryForm): AxiosPromise<CategoryTreeVO[]> => {
        return request({
            url: `/workflow/category/categoryTree`,
            method: 'get',
            params: query
        });
    };

}
export interface CategoryTreeVO {
    id: number | string;
    label: string;
    parentId: number | string;
    weight: number;
    children: CategoryTreeVO[];
}
export interface CategoryVO {
    /**
     * 流程分类ID
     */
    categoryId: string | number;

    /**
     * 父级id
     */
    parentId: string | number;

    /**
     * 流程分类名称
     */
    categoryName: string;

    /**
     * 显示顺序
     */
    orderNum: number;

    /**
     * 创建时间
     */
    createTime: string;

    /**
     * 子对象
     */
    children: CategoryVO[];
}

export interface CategoryForm extends BaseEntity {
    /**
     * 流程分类ID
     */
    categoryId?: string | number;

    /**
     * 流程分类名称
     */
    categoryName?: string;

    /**
     * 父流程分类id
     */
    parentId?: string | number;

    /**
     * 显示顺序
     */
    orderNum?: number;
}

export interface CategoryQuery {
    /**
     * 流程分类名称
     */
    categoryName?: string;
}
